<template>
	<view class="content">
		<view class="title">产品建议</view>
		<view class="textarea">
			<textarea maxlength="200" placeholder="请填写10个字以上的问题描述以便我们提供更好的帮助" placeholder-style="placeholder-class" @input="contenInput"
			 v-model="formData.content"></textarea>
			<view class="font-size">{{textNum}}/200</view>
		</view>
		<view class="title">相关截图</view>

		<view class="imgListBox">
			<view class="addImgBox" v-for="(item,index) in chooseImgList" :key="index">
				<image @click="viewImg(index)" class="imgDiv" :src="item" mode="aspectFill" />
				<view class="delImgBox" @click="delImgItem(index)">
					<image src="../../static/personal/close.png" mode />
				</view>
			</view>
			<view v-if="chooseImgList.length<9" class="addImgBox" @click="chooseImg">
				<image class="addImg" src="../../static/personal/addImg.png" mode />
			</view>
		</view>

		<view class="title">联系方式</view>
		<view>
			<input class="phone-input-box" type="phone" placeholder="邮箱/手机号" maxlength="11" v-model="formData.phone" />
		</view>
		<view class="title2">
			<image class="chosImg" src="../../static/personal/chos_icon.png" mode />允许开发者在48小时内通过客服消息联系我
		</view>
		<view class="submit-box">
			<button class="submit-btn" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		postFileData
	} from "../../sgapi/api.js"
	export default {
		data() {
			return {
				textNum: 0, //    n/200中的n
				chooseImgList: [], //  已经选择好的图片
				formData: {
					content: "",
					phone: "",
					openid: "sdafsdf"
				}
			};
		},
		methods: {
			//   输入控制显示的多少个字
			contenInput(e) {
				this.textNum = e.detail.cursor;
			},


			// 提交反馈
			submit() {
				console.log(666666666666)
				let data = {
					openid: this.formData.openid,
					content: this.formData.content,
					phone: this.formData.phone,
					imgurl: "https://www.baidu.com"
				}
				this.sgAjax.postUserFeedback(data).then(res => {
					this.formData = {
						content: "",
						phone: "",
						openid: "sdafsdf"
					}
					uni.showToast({
						title: "提交成功",
						mask: true
					})
				})
			},

			// 预览图片
			viewImg(index) {
				uni.previewImage({
					current: index,
					urls: this.chooseImgList
				})
			},

			// 删除选择的照片
			delImgItem(index) {
				uni.showModal({
					title: "提示",
					content: "确定要删除这张照片？",
					success: res => {
						if (res.confirm) {
							this.chooseImgList = this.chooseImgList.filter((item, ind) => {
								return index == ind ? null : item;
							});
						}
					}
				});
			},

			// 选择图片
			chooseImg() {
				uni.chooseImage({
					count: 9,
					success: chooseImageRes => {
						let tempFilePaths = chooseImageRes.tempFilePaths;
						let length = this.chooseImgList.length + tempFilePaths.length;
						if (length > 9) {
							uni.showToast({
								mask: true,
								title: "最多上传9张图片！",
								duration: 1500,
								icon: "none"
							});
						} else {
							this.chooseImgList = this.chooseImgList.concat(tempFilePaths);
							console.log(this.chooseImgList);
						}

						//   uni.uploadFile({
						//     url: "https://www.example.com/upload", //仅为示例，非真实的接口地址
						//     filePath: tempFilePaths[0],
						//     name: "file",
						//     formData: {
						//       user: "test"
						//     },
						//     success: uploadFileRes => {
						//       console.log(uploadFileRes.data);
						//     }
						//   });
					}
				});
			}
		}
	};
</script>

<style scoped>
	.content {
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.title {
		font-size: 36rpx;
		color: #040319;
		line-height: 36rpx;
		margin: 32rpx 0;
		font-weight: bold;
	}

	.title2 {
		font-size: 24rpx;
		color: rgba(4, 3, 25, 0.4);
		letter-spacing: 0;
		line-height: 24rpx;
		margin-top: 60rpx;
	}

	.textarea {
		box-shadow: inset 0 0 20px 0 rgba(3, 24, 50, 0.1);
		border-radius: 8px;
		border-radius: 8px;
		padding: 23rpx 32rpx;
	}

	textarea {
		width: 100%;
		height: 240rpx;
	}

	.placeholder-class {
		font-size: 28rpx;
		color: rgba(4, 3, 25, 0.4);
		line-height: 46rpx;
	}

	.font-size {
		font-size: 28rpx;
		color: rgba(4, 3, 25, 0.4);
		text-align: right;
		line-height: 28rpx;
		margin-top: 32rpx;
	}

	.phone-input-box {
		height: 110rpx;
		width: 100%;
		border-top: 1rpx solid rgba(4, 3, 25, 0.1);
		border-bottom: 1rpx solid rgba(4, 3, 25, 0.1);
		line-height: 110rpx;
	}

	/* .phone-input-box-placeholder {
  font-size: 28rpx;
  color: rgba(4, 3, 25, 0.4);
  letter-spacing: 0;
} */

	.chosImg {
		width: 48rpx;
		height: 48rpx;
		vertical-align: middle;
		margin-right: 16rpx;
	}

	.addImgBox {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 130rpx;
		height: 130rpx;
		border-radius: 8rpx;
		border: 1rpx solid rgba(4, 3, 25, 0.2);
		overflow: hidden;
		position: relative;
	}

	.addImg {
		width: 30rpx;
		height: 30rpx;
		display: block;
	}

	.imgListBox {
		display: grid;
		grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
		grid-column-gap: 10rpx;
		grid-row-gap: 10rpx;
	}

	.imgDiv {
		width: 100%;
		height: 100%;
	}

	.delImgBox {
		width: 36rpx;
		height: 36rpx;
		background-color: #ff5756;
		position: absolute;
		right: 0;
		top: 0;
	}

	.delImgBox image {
		width: 36rpx;
		height: 36rpx;
	}

	.submit-btn {
		width: 368rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: #1b82fe;
		box-shadow: 0 8rpx 12rpx -2rpx rgba(0, 98, 216, 0.3);
		border-radius: 8rpx;
		border-radius: 8rpx;
		color: #ffffff;
	}

	.submit-box {
		text-align: center;
		margin-top: 148rpx;
	}
</style>
